<!DOCTYPE html>
<html>
<head>
	<title>NewsManage.html</title>

	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="this is my page">
	<meta http-equiv="content-type" content="text/html; charset=UTF-8">
	<link rel="stylesheet" href="../../../plugins/bootstrap/css/bootstrap.min.css"
		type="text/css"></link>
	<!-- <link rel="stylesheet" href="../../../plugins/FlatUI/dist/css/flat-ui.css"
		type="text/css"></link> -->
	<link rel="shortcut icon" href="../../../plugins/FlatUI/dist/img/favicon.ico">
	<link rel="stylesheet" href="../../../css/style.css">
	<script type="text/javascript" src="../../../js/jquery.js"></script>
	<script type="text/javascript" src="../../../plugins/FlatUI/dist/js/flat-ui.js"></script>
	<script type="text/javascript" src="../../../plugins/bootstrap/js/messager.js"></script>
	<script type="text/javascript" src="../../../js/base.js"></script>
	 <script src="../../../js/template.js"></script>
	<script src="../../../js/bootstrap-paginator.js"></script>
	<script src="../../../js/bootstrap-mypaginator.js"></script>
	
	<script type="text/javascript">
	//分页查询
	function ajaxLoadData(data){
		$.ajax({
			url:commonurl+"/selectAllNews.news",
			type:"POST",
			data:data,
			dataType:"json",
			success:function(data){
				if(data.success){
				obj=data.obj;	
				$('#page_no').val(data.obj.pageNo);
				$('#page_no').attr('data_length',data.obj.list.length);
			 	obj.list.forEach(function(value,index){
						
						value.createTime=new Date(value.createTime) ;
						value.createTime=value.createTime.getFullYear() + "年" + (value.createTime.getMonth() + 1) + "月" + value.createTime.getDate() + "日 " + value.createTime.getHours() + "点" + value.createTime.getMinutes() + "分" + value.createTime.getSeconds() + "秒";
				}) 
				var datas={
	                	sources:obj.list,
	                	commonurlimg:commonurlimg
	            	};
				$("#newsContent").html(template("newsTemplate",datas));
			/* 	obj.list.forEach(function(value,index){
					if(value.status==-1){
				 		$("."+value.id).html("已删除");
				 		$("#"+value.id).html("");
					}
				}) */
				myPaginatorFun("myPages", obj.pageNo, obj.pages);
			}else{
				alert(data.msg);
			}
			}

		})
	}
	
	$(function(){
		//刚进页面加载数据
		var pageNo=sessionStorage.getItem('pageNo')?sessionStorage.getItem('pageNo'):1;
		console.log(pageNo + "aaa")
	 	ajaxLoadData({
			pageNo:pageNo
		}); 
	 	sessionStorage.removeItem('pageNo');
		myoptions.onPageClicked = function(event, originalEvent, type, page) {
			ajaxLoadData({
				pageNo:page
			});
		};
	})
	
	
	function newsModify(id)
	{
		/*  $.messager.confirm("确认删除", "确认要删除吗?删除后不能恢复", function() { 
       			alert("ok pressed");
     		 }); */
    sessionStorage.setItem('newsId',id);
     		 console.log($('#page_no').val())
		   		sessionStorage.setItem('pageNo',$('#page_no').val());
	location.href="newsModify.html"
	}
	
	function newsFindDetail(id)
	{
		/*  $.messager.confirm("确认删除", "确认要删除吗?删除后不能恢复", function() { 
    			alert("ok pressed");
  		 }); */
		  	sessionStorage.setItem('newsId',id);

			location.href="newsDetail.html"
	}
	
	
	
	
		function deleteNews(id)
		{
			 $.messager.confirm("确认删除", "确认要删除吗?删除后不能恢复", function() { 
        			/* alert("ok pressed"); */
        			     $.ajax({
     		            url:commonurl+"/deleteNews.news",
     		            type:"POST",
     		            data:{ "newsId":id,
     		            },
     		            dataType:"json",
     		            success:function(data){
     		            	alert(data.msg);
     		              	if($('#page_no').attr('data_length') == 1){
	    		            	ajaxLoadData({
				    				pageNo:($('#page_no').val() - 1)
				    			})
     		            	return;
     		            	}
    		            	ajaxLoadData({
			    				pageNo:$('#page_no').val()
			    			})
     		            }

     		        })
        			
        			
      		 });
		}
		
		function desmethod()
		{
			alert(1);
		}
	</script>
</head>

<body style="padding: 5px 10px">

		 <input type="hidden"  id="page_no" data_length="" />

	<div class="panel panel-primary">
	  <div class="panel-heading">
	    <h3 class="panel-title">新闻管理</h3>
	  </div>
	  <div class="panel-body">
	  		<a  href="newsAdd.html" class="btn btn-primary btn-default">
	  			添加
	  			<span class="glyphicon glyphicon-plus"></span>
	  		</a>
	  		<table class="table table-hover"  >
	  			<thead>
	  				<tr>
	  					<th style="width:117px;">新闻标题</th>
	  					<th>新闻正文</th>
	  					<th style="width:117px;">创建时间</th>
	  					<th>操作</th>
	  				</tr>
	  			</thead>
	  			<tbody id="newsContent">
	  			<script id="newsTemplate" type="text/html">
	  			{{each sources as i}}
		  			<tr> 	 	 	 	 	 
		  				<td>{{i.newTitle}}</td>
		  				<td>{{i.newContent}}</td>
		  				<td>{{i.createTime}}</td>
		  				<td>
		  					<a class="btn btn-primary  btn-xs btn-warning"  onclick="newsModify('{{i.id}}')" >
		  						修改
		  						<span class="glyphicon glyphicon-pencil"></span>
		  					</a>
		  					<a class="btn btn-primary btn-xs btn-success" onclick="newsFindDetail('{{i.id}}')"  >
		  						详情
		  						<span class="glyphicon glyphicon-list-alt"></span>
		  					</a>
		  					<a class="btn btn-primary btn-xs btn-danger" href="javascript:;" onclick="deleteNews('{{i.id}}')">
		  						删除
		  						<span class="glyphicon glyphicon-remove"></span>
		  					</a>
		  				</td>
		  			</tr>
                 {{/each}}
</script>
<!-- 		  			<tr> 	 	 	 	 	 
		  				<td>兴业银行南京分行阿萨...</td>
		  				<td>兴业银行南京分行阿萨德好啊斯的金卡或冻结卡大口喝酒啊斯的斯的...</td>
		  				<td>2014年10月11日</td>
		  				<td>
		  					<a class="btn btn-primary  btn-xs btn-warning" href="productModify.html">
		  						修改
		  						<span class="glyphicon glyphicon-pencil"></span>
		  					</a>
		  					<a class="btn btn-primary btn-xs btn-success" href="productDetail.html">
		  						详情
		  						<span class="glyphicon glyphicon-list-alt"></span>
		  					</a>
		  					<a class="btn btn-primary btn-xs btn-danger" href="javascript:;" onclick="deleteProduct('1')">
		  						删除
		  						<span class="glyphicon glyphicon-remove"></span>
		  					</a>
		  				</td>
		  			</tr>
		  			<tr> 	 	 	 	 	 
		  				<td>兴业银行南京分行阿萨...</td>
		  				<td>兴业银行南京分行阿萨德好啊斯的金卡或冻结卡大口喝酒啊斯的斯的...</td>
		  				<td>2014年10月11日</td>
		  				<td>
		  					<a class="btn btn-primary  btn-xs btn-warning" href="productModify.html">
		  						修改
		  						<span class="glyphicon glyphicon-pencil"></span>
		  					</a>
		  					<a class="btn btn-primary btn-xs btn-success" href="productDetail.html">
		  						详情
		  						<span class="glyphicon glyphicon-list-alt"></span>
		  					</a>
		  					<a class="btn btn-primary btn-xs btn-danger" href="javascript:;" onclick="deleteProduct('1')">
		  						删除
		  						<span class="glyphicon glyphicon-remove"></span>
		  					</a>
		  				</td>
		  			</tr> -->
	  			</tbody>
	  		</table>
	  </div>
	</div>
		<div style="text-align: center;">
						<ul id="myPages" ></ul>
					</div>
	
</body>
</html>
